class Solution(object):
    def totalHammingDistance(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        total = 0
        n = len(nums)
        for i in range(32):
            count_ones = sum((num >> i) & 1 for num in nums)
            count_zeros = n - count_ones
            total += count_ones * count_zeros
        return total
if __name__ == '__main__':
    nums = [4, 14, 2]
    print(Solution().totalHammingDistance(nums))